package com.starlink.controller.admin;

import com.starlink.common.WebResponse;
import com.starlink.common.annotation.WebAccess;
import com.github.pagehelper.PageInfo;
import com.starlink.model.domain.MallBooksRasDO;
import com.starlink.model.request.MallBooksRasRequest;
import com.starlink.service.MallBooksRasService;
import com.starlink.model.vo.MallBooksRasVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.SortDefault;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author zhanghong
 */
@RestController
@RequestMapping("/admin/mallBooksRas")
@Api(value = "【管理端】商城书籍RAS编码模块", tags = {"【管理端】商城书籍RAS编码模块"})
public class AdminMallBooksRasController {

    @Autowired
    private MallBooksRasService mallBooksRasService;

    @WebAccess(login = true)
    @ApiOperation("检测RAS商品是否审核通过")
    @PostMapping("/check")
    public WebResponse<Boolean> check(@Valid @RequestBody MallBooksRasRequest request) {
        return WebResponse.build(mallBooksRasService.check(request));
    }

    @WebAccess(login = true)
    @ApiOperation("分页查询")
    @PostMapping("/pageQuery")
    public WebResponse<PageInfo<MallBooksRasVO>> pageQuery(@SortDefault(sort = {"create_time"}, direction = Sort.Direction.DESC) Pageable pageable,
                                                           @RequestBody MallBooksRasRequest request) {
        return WebResponse.build(mallBooksRasService.pageQuery(pageable,request));
    }

    @WebAccess(login = true)
    @ApiOperation("新增")
    @PostMapping("/add")
    public WebResponse<Boolean> add(@Valid @RequestBody MallBooksRasRequest request) {
        return WebResponse.build(mallBooksRasService.add(request));
    }

    @WebAccess(login = true)
    @ApiOperation("删除")
    @PostMapping("/delete")
    public WebResponse<Boolean> deleteByKey(@RequestParam("ids") String ids,@RequestParam("specificationId") Long specificationId) {
        return WebResponse.build(mallBooksRasService.deleteDOByIds(ids,specificationId));
    }
}
